/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package laba6;

import interfaces.task6.IOUtils;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Arrays;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import org.junit.Test;

/**
 *
 * @author yakimovich
 */
public class IOUtilsDemo {

    public static void main(String[] args) {
        IOUtilsImpl utils = new IOUtilsImpl();

        //Copying files
        long timeStart = System.nanoTime();
        utils.copyFile("src.pdf", "out.pdf");
        long timeCopyFile = System.nanoTime() - timeStart;
        System.out.printf("%-30s %10s %n", "Total time copying the file by copying without buffering: ", timeCopyFile);

        //Copying files with buffer
        File f1 = new File("src.pdf");
        File f2 = new File("out.pdf");
        timeStart = System.nanoTime();
        utils.copyFileBuffered(f1, f2);
        long timeCopyFileBuffered = System.nanoTime() - timeStart;
        System.out.printf("%-30s %13s %n", "Total time copying the file by copying with buffering: ", timeCopyFileBuffered);

        //Copying files with java.nio
        timeStart = System.nanoTime();
        utils.copyFileBest("src.pdf", "out.pdf");
        long timeCopyFileBest = System.nanoTime() - timeStart;
        System.out.printf("%-30s %36s %n", "The best time copying the file: ", timeCopyFileBest);

        //Search for files
        String [] files = utils.findFiles(".\\src\\");
        for (String file : files){
            System.out.println(file);
        }

        //Search for files with the specified extension
        System.out.println(Arrays.toString(utils.findFiles("d:\\temp\\", ".java")));
    }
}
